package edu.yngsxy.dsstudyApi.core.ai;


import cn.hutool.ai.AIServiceFactory;
import cn.hutool.ai.ModelName;
import cn.hutool.ai.core.AIConfigBuilder;
import cn.hutool.ai.model.deepseek.DeepSeekService;
import cn.hutool.ai.model.doubao.DoubaoService;
import edu.yngsxy.dsstudyApi.core.model.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * AI大模型
 */
@RestController
@RequestMapping("/api/v1/ai/")
@Tag(name = "AI大模型") // 分组标签
@Slf4j
public class AIController {
    @Value("${ai.doubao.apikey}")
    private String doubaoApikey;
    @Value("${ai.doubao.model}")
    private String doubaoModel;
    @Value("${ai.deepseek.apikey}")
    private String deepseekApikey;
    @Value("${ai.deepseek.model}")
    private String deepseekModel;
    DoubaoService doubaoService;// 豆包服务
    DeepSeekService deepSeekService;// deepseek服务

    @PostConstruct
    public void init() {// 初始化豆包服务
        doubaoService = AIServiceFactory.getAIService(new AIConfigBuilder(ModelName.DOUBAO.getValue()).setApiKey(doubaoApikey).setModel(doubaoModel).build(), DoubaoService.class);
        deepSeekService = AIServiceFactory.getAIService(new AIConfigBuilder(ModelName.DEEPSEEK.getValue()).setApiKey(deepseekApikey).setModel(deepseekModel).build(), DeepSeekService.class);

    }
    @PostMapping("deepseek-chat")
    @Operation(summary = "deepseek-单论对话", description = "单论对话")
    public Result<String> deepseekChat(
            @Parameter(description = "发送消息", required = true)
            @RequestBody ChatMessage chatMessage) {
        String answer= deepSeekService.chat(chatMessage.msg());
        return Result.<String>success(answer);
    }

    record ChatMessage(String msg) {}//定义消息体接收客户端json数据

}
